package com.java.zhuiyun.api.course_unit.controller;

import com.java.zhuiyun.api.course_unit.entity.CourseUnit;
import com.java.zhuiyun.api.course_unit.service.CourseUnitService;
import com.java.zhuiyun.api.file_manager.entity.FileManager;
import com.java.zhuiyun.common.response.CommonResult;
import com.java.zhuiyun.util.pageUtil.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName CourseUnitController
 * @Description TODO
 * @Author 杨友朋
 * @Date 2023/8/15 19:54
 **/
@RestController
@RequestMapping("/course_unit")
@CrossOrigin
public class CourseUnitController {
    @Resource
    CourseUnitService courseUnitService;

    /**
     * @Author 杨友朋
     * @Description TODO 查询章节
     * @Date 2023/8/15 20:56
     * @Return
     * @param
     */
    @GetMapping("/selectUnit")
    public CommonResult selectUnit(Integer courseId, PageRequest pageRequest){
        return CommonResult.ok(courseUnitService.selectUnit(courseId,pageRequest));
    }

    /**
    * @Author 杨友朋
    * @Description TODO 单查章节
    * @Date 2023/8/24 9:00
    * @Return
    * @param
    */
    @GetMapping("/selectUnitById")
    public CommonResult selectUnitById(Integer id){
        return courseUnitService.selectUnitById(id);
    }
    /**
     * @Author 杨友朋
     * @Description TODO 添加章节
     * @Date 2023/8/15 20:55
     * @Return
     * @param
     */
    @PostMapping("/addUnit")
    public CommonResult addUnit(@RequestBody CourseUnit courseUnit){
        return courseUnitService.addUnit(courseUnit);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 修改章节
    * @Date 2023/8/21 16:00
    * @Return
    * @param
    */
    @PostMapping("/updateUnit")
    public CommonResult updateUnit(@RequestBody CourseUnit courseUnit){
        return courseUnitService.updateUnit(courseUnit);
    }
    /**
    * @Author 杨友朋
    * @Description TODO 更改状态
    * @Date 2023/8/24 9:23
    * @Return
    * @param
    */
    @GetMapping("/upSwitch")
    public CommonResult upSwitch(CourseUnit courseUnit){
        return courseUnitService.upSwitch(courseUnit);
    }
    /**
    * @Author 杨友朋
    * @Description TODO 删除章节
    * @Date 2023/8/21 16:18
    * @Return
    * @param
    */
    @GetMapping("/delUnit")
    public CommonResult delUnit(Integer id){
        return courseUnitService.delUnit(id);
    }

    /**
    * @Author MJL
    * @Description todo 章节内添加视频
    * @Date 2023/8/17 10:12
    * @Return  * @param null
    */
    @PostMapping("/addFile")
    public CommonResult addFile(@RequestBody CourseUnit courseUnit) {
        Integer i = courseUnitService.addFile(courseUnit);
        if (i >= 0) {
            return CommonResult.ok("恭喜您，添加视频成功");
        } else {
            return CommonResult.error("很抱歉，添加视频失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 查询可以添加的视频
    * @Date 2023/8/17 14:23
    * @Return  * @param null
    */
    @GetMapping("/selectFile")
    public CommonResult selectFile(String fileType) {
        List<FileManager> list = courseUnitService.selectFile(fileType);
        if (list != null) {
            return CommonResult.ok(list);
        } else {
            return CommonResult.error(9999,"视频获取失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 将章节进行下架操作
    * @Date 2023/9/2 21:12
    * @Return  * @param null
    */
    @PostMapping("/banned")
    public CommonResult banned(Integer id) {
        return CommonResult.ok(courseUnitService.banned(id));
    }
    /**
    * @Author MJL
    * @Description todo 将章节进行上架操作
    * @Date 2023/9/2 21:26
    * @Return  * @param null
    */
    @PostMapping("/enables")
    public CommonResult enables(Integer id) {
        return CommonResult.ok(courseUnitService.enables(id));
    }
}
